package com.cardvalue.sys.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.cardvalue.sys.R;
import com.cardvalue.sys.base.BaseActivity;
import butterknife.Bind;
import butterknife.ButterKnife;

/**
 *html5 页面的显示
 */
public class LoadWebPage extends BaseActivity {
    @Bind(R.id.webView1) WebView wv ;
    @Bind(R.id.tv_center) TextView tv;
    private String welcome;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loadwebpage);
        ButterKnife.bind(this);
        setHeaderFields(0, R.string.my_application,0,R.mipmap.back, 0,0);
        welcome = getIntent().getStringExtra("welcome")==null?"":getIntent().getStringExtra("welcome").toString();
        tv.setText(getIntent().getStringExtra("title"));
        if(welcome.equals("welcome")){
            findViewById(R.id.iv_left).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(LoadWebPage.this,HomeActivity.class));
                    LoadWebPage.this.finish();
                }
            });
        }
        WebSettings setting = wv.getSettings();
        setting.setJavaScriptEnabled(true);
        wv.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
              //  dialog.cancel();
                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
               // dialog.cancel();
                super.onReceivedError(view, errorCode, description, failingUrl);
                findViewById(R.id.img_home).setVisibility(View.VISIBLE);
                wv.setVisibility(View.GONE);
            }
        });
        wv.loadUrl(getIntent().getStringExtra("url"));
    }

}
